<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>校园迎新管理系统</title>
    <!-- 引入 UIkit 国内源 -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/uikit/3.16.19/css/uikit.min.css">
    <script src="https://cdn.staticfile.org/uikit/3.16.19/js/uikit.min.js"></script>
    <script src="https://cdn.staticfile.org/uikit/3.16.19/js/uikit-icons.min.js"></script>
    <style>
        body {
            display: flex;
        }

        .sidebar {
            width: 20%;
            height: 100vh;
            background-color: #f8f9fa;
            padding: 1rem;
        }

        .main-content {
            flex: 1;
            padding: 1rem;
        }
    </style>
</head>

<body>
    <div class="sidebar">
        <ul class="uk-nav uk-nav-default" uk-switcher="connect: #content-tabs">
            <li class="uk-active"><a href="#">新生信息</a></li>
            <li><a href="#">住宿安排</a></li>
            <li><a href="#">报到记录</a></li>
            <li><a href="#">志愿者信息</a></li>
            <li><a href="#">迎新活动</a></li>
        </ul>
    </div>
    <div class="main-content">
        <ul id="content-tabs" class="uk-switcher">
            <!-- 新生信息 -->
            <li>
                <h2>新生信息</h2>
                <input type="text" id="newStudentSearch" placeholder="搜索新生信息" oninput="searchNewStudents()">
                <button class="uk-button uk-button-primary" onclick="openAddNewStudentModal()">添加新生信息</button>
                <table class="uk-table uk-table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>姓名</th>
                            <th>专业</th>
                            <th>联系方式</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="newStudentTableBody"></tbody>
                </table>
            </li>
            <!-- 住宿安排 -->
            <li>
                <h2>住宿安排</h2>
                <input type="text" id="accommodationSearch" placeholder="搜索住宿安排" oninput="searchAccommodation()">
                <button class="uk-button uk-button-primary" onclick="openAddAccommodationModal()">添加住宿安排</button>
                <table class="uk-table uk-table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>学生姓名</th>
                            <th>宿舍号</th>
                            <th>楼层</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="accommodationTableBody"></tbody>
                </table>
            </li>
            <!-- 报到记录 -->
            <li>
                <h2>报到记录</h2>
                <input type="text" id="registrationSearch" placeholder="搜索报到记录" oninput="searchRegistration()">
                <button class="uk-button uk-button-primary" onclick="openAddRegistrationModal()">添加报到记录</button>
                <table class="uk-table uk-table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>学生姓名</th>
                            <th>报到时间</th>
                            <th>报到状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="registrationTableBody"></tbody>
                </table>
            </li>
            <!-- 志愿者信息 -->
            <li>
                <h2>志愿者信息</h2>
                <input type="text" id="volunteerSearch" placeholder="搜索志愿者信息" oninput="searchVolunteers()">
                <button class="uk-button uk-button-primary" onclick="openAddVolunteerModal()">添加志愿者信息</button>
                <table class="uk-table uk-table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>姓名</th>
                            <th>服务区域</th>
                            <th>联系方式</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="volunteerTableBody"></tbody>
                </table>
            </li>
            <!-- 迎新活动 -->
            <li>
                <h2>迎新活动</h2>
                <input type="text" id="activitySearch" placeholder="搜索迎新活动" oninput="searchActivities()">
                <button class="uk-button uk-button-primary" onclick="openAddActivityModal()">添加迎新活动</button>
                <table class="uk-table uk-table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>活动名称</th>
                            <th>活动时间</th>
                            <th>活动地点</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="activityTableBody"></tbody>
                </table>
            </li>
        </ul>
    </div>

    <!-- 新生信息添加/编辑模态框 -->
    <div id="newStudentModal" uk-modal>
        <div class="uk-modal-dialog uk-modal-body">
            <h2 class="uk-modal-title">添加/编辑新生信息</h2>
            <input type="hidden" id="newStudentId">
            <label for="newStudentName">姓名</label>
            <input class="uk-input" type="text" id="newStudentName">
            <label for="newStudentMajor">专业</label>
            <input class="uk-input" type="text" id="newStudentMajor">
            <label for="newStudentContact">联系方式</label>
            <input class="uk-input" type="text" id="newStudentContact">
            <p class="uk-text-right">
                <button class="uk-button uk-button-default uk-modal-close" type="button">关闭</button>
                <button class="uk-button uk-button-primary" onclick="saveNewStudent()">保存</button>
            </p>
        </div>
    </div>

    <!-- 住宿安排添加/编辑模态框 -->
    <div id="accommodationModal" uk-modal>
        <div class="uk-modal-dialog uk-modal-body">
            <h2 class="uk-modal-title">添加/编辑住宿安排</h2>
            <input type="hidden" id="accommodationId">
            <label for="accommodationStudentName">学生姓名</label>
            <input class="uk-input" type="text" id="accommodationStudentName">
            <label for="accommodationRoomNumber">宿舍号</label>
            <input class="uk-input" type="text" id="accommodationRoomNumber">
            <label for="accommodationFloor">楼层</label>
            <input class="uk-input" type="text" id="accommodationFloor">
            <p class="uk-text-right">
                <button class="uk-button uk-button-default uk-modal-close" type="button">关闭</button>
                <button class="uk-button uk-button-primary" onclick="saveAccommodation()">保存</button>
            </p>
        </div>
    </div>

    <!-- 报到记录添加/编辑模态框 -->
    <div id="registrationModal" uk-modal>
        <div class="uk-modal-dialog uk-modal-body">
            <h2 class="uk-modal-title">添加/编辑报到记录</h2>
            <input type="hidden" id="registrationId">
            <label for="registrationStudentName">学生姓名</label>
            <input class="uk-input" type="text" id="registrationStudentName">
            <label for="registrationTime">报到时间</label>
            <input class="uk-input" type="datetime-local" id="registrationTime">
            <label for="registrationStatus">报到状态</label>
            <input class="uk-input" type="text" id="registrationStatus">
            <p class="uk-text-right">
                <button class="uk-button uk-button-default uk-modal-close" type="button">关闭</button>
                <button class="uk-button uk-button-primary" onclick="saveRegistration()">保存</button>
            </p>
        </div>
    </div>

    <!-- 志愿者信息添加/编辑模态框 -->
    <div id="volunteerModal" uk-modal>
        <div class="uk-modal-dialog uk-modal-body">
            <h2 class="uk-modal-title">添加/编辑志愿者信息</h2>
            <input type="hidden" id="volunteerId">
            <label for="volunteerName">姓名</label>
            <input class="uk-input" type="text" id="volunteerName">
            <label for="volunteerArea">服务区域</label>
            <input class="uk-input" type="text" id="volunteerArea">
            <label for="volunteerContact">联系方式</label>
            <input class="uk-input" type="text" id="volunteerContact">
            <p class="uk-text-right">
                <button class="uk-button uk-button-default uk-modal-close" type="button">关闭</button>
                <button class="uk-button uk-button-primary" onclick="saveVolunteer()">保存</button>
            </p>
        </div>
    </div>

    <!-- 迎新活动添加/编辑模态框 -->
    <div id="activityModal" uk-modal>
        <div class="uk-modal-dialog uk-modal-body">
            <h2 class="uk-modal-title">添加/编辑迎新活动</h2>
            <input type="hidden" id="activityId">
            <label for="activityName">活动名称</label>
            <input class="uk-input" type="text" id="activityName">
            <label for="activityTime">活动时间</label>
            <input class="uk-input" type="datetime-local" id="activityTime">
            <label for="activityLocation">活动地点</label>
            <input class="uk-input" type="text" id="activityLocation">
            <p class="uk-text-right">
                <button class="uk-button uk-button-default uk-modal-close" type="button">关闭</button>
                <button class="uk-button uk-button-primary" onclick="saveActivity()">保存</button>
            </p>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            initNewStudents();
            initAccommodation();
            initRegistration();
            initVolunteers();
            initWelcomeActivities();
        });

        // 新生信息管理
        function initNewStudents() {
            let newStudents = JSON.parse(localStorage.getItem('newStudents')) || [
                { id: 1, name: '张三', major: '计算机科学与技术', contact: '13800138001' },
                { id: 2, name: '李四', major: '软件工程', contact: '13800138002' },
                { id: 3, name: '王五', major: '信息安全', contact: '13800138003' },
                { id: 4, name: '赵六', major: '数据科学与大数据技术', contact: '13800138004' },
                { id: 5, name: '孙七', major: '人工智能', contact: '13800138005' },
                { id: 6, name: '周八', major: '物联网工程', contact: '13800138006' },
                { id: 7, name: '吴九', major: '网络工程', contact: '13800138007' },
                { id: 8, name: '郑十', major: '数字媒体技术', contact: '13800138008' },
                { id: 9, name: '王十一', major: '通信工程', contact: '13800138009' },
                { id: 10, name: '李十二', major: '电子信息工程', contact: '13800138010' }
            ];
            localStorage.setItem('newStudents', JSON.stringify(newStudents));
            renderNewStudents(newStudents);
        }

        function renderNewStudents(newStudents) {
            let tableBody = document.getElementById('newStudentTableBody');
            tableBody.innerHTML = '';
            newStudents.forEach(student => {
                let row = tableBody.insertRow();
                row.insertCell(0).textContent = student.id;
                row.insertCell(1).textContent = student.name;
                row.insertCell(2).textContent = student.major;
                row.insertCell(3).textContent = student.contact;
                let actionsCell = row.insertCell(4);
                actionsCell.innerHTML = `<button class="uk-button uk-button-default" onclick="openEditNewStudentModal(${student.id})">编辑</button>
                                         <button class="uk-button uk-button-danger" onclick="deleteNewStudent(${student.id})">删除</button>`;
            });
        }

        function openAddNewStudentModal() {
            document.getElementById('newStudentId').value = '';
            document.getElementById('newStudentName').value = '';
            document.getElementById('newStudentMajor').value = '';
            document.getElementById('newStudentContact').value = '';
            UIkit.modal('#newStudentModal').show();
        }

        function openEditNewStudentModal(id) {
            let newStudents = JSON.parse(localStorage.getItem('newStudents'));
            let student = newStudents.find(s => s.id === id);
            document.getElementById('newStudentId').value = student.id;
            document.getElementById('newStudentName').value = student.name;
            document.getElementById('newStudentMajor').value = student.major;
            document.getElementById('newStudentContact').value = student.contact;
            UIkit.modal('#newStudentModal').show();
        }

        function saveNewStudent() {
            let newStudents = JSON.parse(localStorage.getItem('newStudents'));
            let id = document.getElementById('newStudentId').value;
            let name = document.getElementById('newStudentName').value;
            let major = document.getElementById('newStudentMajor').value;
            let contact = document.getElementById('newStudentContact').value;
            if (id) {
                let index = newStudents.findIndex(s => s.id === parseInt(id));
                newStudents[index] = { id: parseInt(id), name, major, contact };
            } else {
                let newId = newStudents.length > 0 ? Math.max(...newStudents.map(s => s.id)) + 1 : 1;
                newStudents.push({ id: newId, name, major, contact });
            }
            localStorage.setItem('newStudents', JSON.stringify(newStudents));
            renderNewStudents(newStudents);
            UIkit.modal('#newStudentModal').hide();
        }

        function deleteNewStudent(id) {
            let newStudents = JSON.parse(localStorage.getItem('newStudents'));
            newStudents = newStudents.filter(s => s.id!== id);
            localStorage.setItem('newStudents', JSON.stringify(newStudents));
            renderNewStudents(newStudents);
        }

        function searchNewStudents() {
            let searchTerm = document.getElementById('newStudentSearch').value.toLowerCase();
            let newStudents = JSON.parse(localStorage.getItem('newStudents'));
            let filteredStudents = newStudents.filter(student => student.name.toLowerCase().includes(searchTerm) || student.major.toLowerCase().includes(searchTerm));
            renderNewStudents(filteredStudents);
        }

        // 住宿安排管理
        function initAccommodation() {
            let accommodation = JSON.parse(localStorage.getItem('accommodation')) || [
                { id: 1, studentName: '张三', roomNumber: '101', floor: '1' },
                { id: 2, studentName: '李四', roomNumber: '102', floor: '1' },
                { id: 3, studentName: '王五', roomNumber: '103', floor: '1' },
                { id: 4, studentName: '赵六', roomNumber: '201', floor: '2' },
                { id: 5, studentName: '孙七', roomNumber: '202', floor: '2' },
                { id: 6, studentName: '周八', roomNumber: '203', floor: '2' },
                { id: 7, studentName: '吴九', roomNumber: '301', floor: '3' },
                { id: 8, studentName: '郑十', roomNumber: '302', floor: '3' },
                { id: 9, studentName: '王十一', roomNumber: '303', floor: '3' },
                { id: 10, studentName: '李十二', roomNumber: '401', floor: '4' }
            ];
            localStorage.setItem('accommodation', JSON.stringify(accommodation));
            renderAccommodation(accommodation);
        }

        function renderAccommodation(accommodation) {
            let tableBody = document.getElementById('accommodationTableBody');
            tableBody.innerHTML = '';
            accommodation.forEach(item => {
                let row = tableBody.insertRow();
                row.insertCell(0).textContent = item.id;
                row.insertCell(1).textContent = item.studentName;
                row.insertCell(2).textContent = item.roomNumber;
                row.insertCell(3).textContent = item.floor;
                let actionsCell = row.insertCell(4);
                actionsCell.innerHTML = `<button class="uk-button uk-button-default" onclick="openEditAccommodationModal(${item.id})">编辑</button>
                                         <button class="uk-button uk-button-danger" onclick="deleteAccommodation(${item.id})">删除</button>`;
            });
        }

        function openAddAccommodationModal() {
            document.getElementById('accommodationId').value = '';
            document.getElementById('accommodationStudentName').value = '';
            document.getElementById('accommodationRoomNumber').value = '';
            document.getElementById('accommodationFloor').value = '';
            UIkit.modal('#accommodationModal').show();
        }

        function openEditAccommodationModal(id) {
            let accommodation = JSON.parse(localStorage.getItem('accommodation'));
            let item = accommodation.find(a => a.id === id);
            document.getElementById('accommodationId').value = item.id;
            document.getElementById('accommodationStudentName').value = item.studentName;
            document.getElementById('accommodationRoomNumber').value = item.roomNumber;
            document.getElementById('accommodationFloor').value = item.floor;
            UIkit.modal('#accommodationModal').show();
        }

        function saveAccommodation() {
            let accommodation = JSON.parse(localStorage.getItem('accommodation'));
            let id = document.getElementById('accommodationId').value;
            let studentName = document.getElementById('accommodationStudentName').value;
            let roomNumber = document.getElementById('accommodationRoomNumber').value;
            let floor = document.getElementById('accommodationFloor').value;
            if (id) {
                let index = accommodation.findIndex(a => a.id === parseInt(id));
                accommodation[index] = { id: parseInt(id), studentName, roomNumber, floor };
            } else {
                let newId = accommodation.length > 0 ? Math.max(...accommodation.map(a => a.id)) + 1 : 1;
                accommodation.push({ id: newId, studentName, roomNumber, floor });
            }
            localStorage.setItem('accommodation', JSON.stringify(accommodation));
            renderAccommodation(accommodation);
            UIkit.modal('#accommodationModal').hide();
        }

        function deleteAccommodation(id) {
            let accommodation = JSON.parse(localStorage.getItem('accommodation'));
            accommodation = accommodation.filter(a => a.id!== id);
            localStorage.setItem('accommodation', JSON.stringify(accommodation));
            renderAccommodation(accommodation);
        }

        function searchAccommodation() {
            let searchTerm = document.getElementById('accommodationSearch').value.toLowerCase();
            let accommodation = JSON.parse(localStorage.getItem('accommodation'));
            let filteredAccommodation = accommodation.filter(item => item.studentName.toLowerCase().includes(searchTerm) || item.roomNumber.toLowerCase().includes(searchTerm));
            renderAccommodation(filteredAccommodation);
        }

        // 报到记录管理
        function initRegistration() {
            let registration = JSON.parse(localStorage.getItem('registration')) || [
                { id: 1, studentName: '张三', time: '2024-09-01T09:00', status: '已报到' },
                { id: 2, studentName: '李四', time: '2024-09-01T10:00', status: '已报到' },
                { id: 3, studentName: '王五', time: '2024-09-01T11:00', status: '已报到' },
                { id: 4, studentName: '赵六', time: '2024-09-02T09:00', status: '已报到' },
                { id: 5, studentName: '孙七', time: '2024-09-02T10:00', status: '已报到' },
                { id: 6, studentName: '周八', time: '2024-09-02T11:00', status: '已报到' },
                { id: 7, studentName: '吴九', time: '2024-09-03T09:00', status: '已报到' },
                { id: 8, studentName: '郑十', time: '2024-09-03T10:00', status: '已报到' },
                { id: 9, studentName: '王十一', time: '2024-09-03T11:00', status: '已报到' },
                { id: 10, studentName: '李十二', time: '2024-09-04T09:00', status: '已报到' }
            ];
            localStorage.setItem('registration', JSON.stringify(registration));
            renderRegistration(registration);
        }

        function renderRegistration(registration) {
            let tableBody = document.getElementById('registrationTableBody');
            tableBody.innerHTML = '';
            registration.forEach(record => {
                let row = tableBody.insertRow();
                row.insertCell(0).textContent = record.id;
                row.insertCell(1).textContent = record.studentName;
                row.insertCell(2).textContent = record.time;
                row.insertCell(3).textContent = record.status;
                let actionsCell = row.insertCell(4);
                actionsCell.innerHTML = `<button class="uk-button uk-button-default" onclick="openEditRegistrationModal(${record.id})">编辑</button>
                                         <button class="uk-button uk-button-danger" onclick="deleteRegistration(${record.id})">删除</button>`;
            });
        }

        function openAddRegistrationModal() {
            document.getElementById('registrationId').value = '';
            document.getElementById('registrationStudentName').value = '';
            document.getElementById('registrationTime').value = '';
            document.getElementById('registrationStatus').value = '';
            UIkit.modal('#registrationModal').show();
        }

        function openEditRegistrationModal(id) {
            let registration = JSON.parse(localStorage.getItem('registration'));
            let record = registration.find(r => r.id === id);
            document.getElementById('registrationId').value = record.id;
            document.getElementById('registrationStudentName').value = record.studentName;
            document.getElementById('registrationTime').value = record.time;
            document.getElementById('registrationStatus').value = record.status;
            UIkit.modal('#registrationModal').show();
        }

        function saveRegistration() {
            let registration = JSON.parse(localStorage.getItem('registration'));
            let id = document.getElementById('registrationId').value;
            let studentName = document.getElementById('registrationStudentName').value;
            let time = document.getElementById('registrationTime').value;
            let status = document.getElementById('registrationStatus').value;
            if (id) {
                let index = registration.findIndex(r => r.id === parseInt(id));
                registration[index] = { id: parseInt(id), studentName, time, status };
            } else {
                let newId = registration.length > 0 ? Math.max(...registration.map(r => r.id)) + 1 : 1;
                registration.push({ id: newId, studentName, time, status });
            }
            localStorage.setItem('registration', JSON.stringify(registration));
            renderRegistration(registration);
            UIkit.modal('#registrationModal').hide();
        }

        function deleteRegistration(id) {
            let registration = JSON.parse(localStorage.getItem('registration'));
            registration = registration.filter(r => r.id!== id);
            localStorage.setItem('registration', JSON.stringify(registration));
            renderRegistration(registration);
        }

        function searchRegistration() {
            let searchTerm = document.getElementById('registrationSearch').value.toLowerCase();
            let registration = JSON.parse(localStorage.getItem('registration'));
            let filteredRegistration = registration.filter(record => record.studentName.toLowerCase().includes(searchTerm) || record.status.toLowerCase().includes(searchTerm));
            renderRegistration(filteredRegistration);
        }

        // 志愿者信息管理
        function initVolunteers() {
            let volunteers = JSON.parse(localStorage.getItem('volunteers')) || [
                { id: 1, name: '志愿者 A', area: '报到区', contact: '13900139001' },
                { id: 2, name: '志愿者 B', area: '住宿区', contact: '13900139002' },
                { id: 3, name: '志愿者 C', area: '活动区', contact: '13900139003' },
                { id: 4, name: '志愿者 D', area: '报到区', contact: '13900139004' },
                { id: 5, name: '志愿者 E', area: '住宿区', contact: '13900139005' },
                { id: 6, name: '志愿者 F', area: '活动区', contact: '13900139006' },
                { id: 7, name: '志愿者 G', area: '报到区', contact: '13900139007' },
                { id: 8, name: '志愿者 H', area: '住宿区', contact: '13900139008' },
                { id: 9, name: '志愿者 I', area: '活动区', contact: '13900139009' },
                { id: 10, name: '志愿者 J', area: '报到区', contact: '13900139010' }
            ];
            localStorage.setItem('volunteers', JSON.stringify(volunteers));
            renderVolunteers(volunteers);
        }

        function renderVolunteers(volunteers) {
            let tableBody = document.getElementById('volunteerTableBody');
            tableBody.innerHTML = '';
            volunteers.forEach(volunteer => {
                let row = tableBody.insertRow();
                row.insertCell(0).textContent = volunteer.id;
                row.insertCell(1).textContent = volunteer.name;
                row.insertCell(2).textContent = volunteer.area;
                row.insertCell(3).textContent = volunteer.contact;
                let actionsCell = row.insertCell(4);
                actionsCell.innerHTML = `<button class="uk-button uk-button-default" onclick="openEditVolunteerModal(${volunteer.id})">编辑</button>
                                         <button class="uk-button uk-button-danger" onclick="deleteVolunteer(${volunteer.id})">删除</button>`;
            });
        }

        function openAddVolunteerModal() {
            document.getElementById('volunteerId').value = '';
            document.getElementById('volunteerName').value = '';
            document.getElementById('volunteerArea').value = '';
            document.getElementById('volunteerContact').value = '';
            UIkit.modal('#volunteerModal').show();
        }

        function openEditVolunteerModal(id) {
            let volunteers = JSON.parse(localStorage.getItem('volunteers'));
            let volunteer = volunteers.find(v => v.id === id);
            document.getElementById('volunteerId').value = volunteer.id;
            document.getElementById('volunteerName').value = volunteer.name;
            document.getElementById('volunteerArea').value = volunteer.area;
            document.getElementById('volunteerContact').value = volunteer.contact;
            UIkit.modal('#volunteerModal').show();
        }

        function saveVolunteer() {
            let volunteers = JSON.parse(localStorage.getItem('volunteers'));
            let id = document.getElementById('volunteerId').value;
            let name = document.getElementById('volunteerName').value;
            let area = document.getElementById('volunteerArea').value;
            let contact = document.getElementById('volunteerContact').value;
            if (id) {
                let index = volunteers.findIndex(v => v.id === parseInt(id));
                volunteers[index] = { id: parseInt(id), name, area, contact };
            } else {
                let newId = volunteers.length > 0 ? Math.max(...volunteers.map(v => v.id)) + 1 : 1;
                volunteers.push({ id: newId, name, area, contact });
            }
            localStorage.setItem('volunteers', JSON.stringify(volunteers));
            renderVolunteers(volunteers);
            UIkit.modal('#volunteerModal').hide();
        }

        function deleteVolunteer(id) {
            let volunteers = JSON.parse(localStorage.getItem('volunteers'));
            volunteers = volunteers.filter(v => v.id!== id);
            localStorage.setItem('volunteers', JSON.stringify(volunteers));
            renderVolunteers(volunteers);
        }

        function searchVolunteers() {
            let searchTerm = document.getElementById('volunteerSearch').value.toLowerCase();
            let volunteers = JSON.parse(localStorage.getItem('volunteers'));
            let filteredVolunteers = volunteers.filter(volunteer => volunteer.name.toLowerCase().includes(searchTerm) || volunteer.area.toLowerCase().includes(searchTerm));
            renderVolunteers(filteredVolunteers);
        }

        // 迎新活动管理
        function initWelcomeActivities() {
            let activities = JSON.parse(localStorage.getItem('welcomeActivities')) || [
                { id: 1, name: '新生开学典礼', time: '2024-09-05T09:00', location: '学校礼堂' },
                { id: 2, name: '专业介绍会', time: '2024-09-05T14:00', location: '各专业教室' },
                { id: 3, name: '校园参观活动', time: '2024-09-06T09:00', location: '校园内' },
                { id: 4, name: '社团招新活动', time: '2024-09-06T14:00', location: '学校广场' },
                { id: 5, name: '学长学姐经验分享会', time: '2024-09-07T09:00', location: '各专业教室' },
                { id: 6, name: '心理健康讲座', time: '2024-09-07T14:00', location: '学校报告厅' },
                { id: 7, name: '安全教育讲座', time: '2024-09-08T09:00', location: '学校报告厅' },
                { id: 8, name: '宿舍文化活动', time: '2024-09-08T14:00', location: '各宿舍楼' },
                { id: 9, name: '体育活动比赛', time: '2024-09-09T09:00', location: '学校操场' },
                { id: 10, name: '文艺晚会', time: '2024-09-09T19:00', location: '学校礼堂' }
            ];
            localStorage.setItem('welcomeActivities', JSON.stringify(activities));
            renderWelcomeActivities(activities);
        }

        function renderWelcomeActivities(activities) {
            let tableBody = document.getElementById('activityTableBody');
            tableBody.innerHTML = '';
            activities.forEach(activity => {
                let row = tableBody.insertRow();
                row.insertCell(0).textContent = activity.id;
                row.insertCell(1).textContent = activity.name;
                row.insertCell(2).textContent = activity.time;
                row.insertCell(3).textContent = activity.location;
                let actionsCell = row.insertCell(4);
                actionsCell.innerHTML = `<button class="uk-button uk-button-default" onclick="openEditActivityModal(${activity.id})">编辑</button>
                                         <button class="uk-button uk-button-danger" onclick="deleteActivity(${activity.id})">删除</button>`;
            });
        }

        function openAddActivityModal() {
            document.getElementById('activityId').value = '';
            document.getElementById('activityName').value = '';
            document.getElementById('activityTime').value = '';
            document.getElementById('activityLocation').value = '';
            UIkit.modal('#activityModal').show();
        }

        function openEditActivityModal(id) {
            let activities = JSON.parse(localStorage.getItem('welcomeActivities'));
            let activity = activities.find(a => a.id === id);
            document.getElementById('activityId').value = activity.id;
            document.getElementById('activityName').value = activity.name;
            document.getElementById('activityTime').value = activity.time;
            document.getElementById('activityLocation').value = activity.location;
            UIkit.modal('#activityModal').show();
        }

        function saveActivity() {
            let activities = JSON.parse(localStorage.getItem('welcomeActivities'));
            let id = document.getElementById('activityId').value;
            let name = document.getElementById('activityName').value;
            let time = document.getElementById('activityTime').value;
            let location = document.getElementById('activityLocation').value;
            if (id) {
                let index = activities.findIndex(a => a.id === parseInt(id));
                activities[index] = { id: parseInt(id), name, time, location };
            } else {
                let newId = activities.length > 0 ? Math.max(...activities.map(a => a.id)) + 1 : 1;
                activities.push({ id: newId, name, time, location });
            }
            localStorage.setItem('welcomeActivities', JSON.stringify(activities));
            renderWelcomeActivities(activities);
            UIkit.modal('#activityModal').hide();
        }

        function deleteActivity(id) {
            let activities = JSON.parse(localStorage.getItem('welcomeActivities'));
            activities = activities.filter(a => a.id!== id);
            localStorage.setItem('welcomeActivities', JSON.stringify(activities));
            renderWelcomeActivities(activities);
        }

        function searchActivities() {
            let searchTerm = document.getElementById('activitySearch').value.toLowerCase();
            let activities = JSON.parse(localStorage.getItem('welcomeActivities'));
            let filteredActivities = activities.filter(activity => activity.name.toLowerCase().includes(searchTerm) || activity.location.toLowerCase().includes(searchTerm));
            renderWelcomeActivities(filteredActivities);
        }
    </script>
</body>

</html>